package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.WebService;

import java.util.HashMap;
import java.util.Map;

/**
 * IVPN_WebService_Imp_Getivpnkhxx
 * 客户查询（IVPN网站）
 * @author xuzhi
 *
 */
public class IVPN_WebService_Imp_Getivpnkhxx implements WorkInterFace {

	@Override
	public String getName() {
		return "IVPN客户查询（IVPN网站）";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[1];
		in[0]=new Attr("mdn","mdn", AttrType.TYPE_String,true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[17];
		out[0]=new Attr("ReturnCode", "0：成功；其它：失败", AttrType.TYPE_Int, true);
		out[1]=new Attr("Report", "返回report", AttrType.TYPE_String, true);
		out[2]=new Attr("客户名称", "客户名称", AttrType.TYPE_String, true);
		out[3]=new Attr("客户号", "客户号", AttrType.TYPE_String, true);
		out[4]=new Attr("客户状态", "客户状态", AttrType.TYPE_String, true);
		out[5]=new Attr("分机短号最大长度", "分机短号最大长度", AttrType.TYPE_String, true);
		out[6]=new Attr("网内呼叫计费类别", "网内呼叫计费类别", AttrType.TYPE_String, true);
		out[7]=new Attr("物理号码", "物理号码", AttrType.TYPE_String, true);
		out[8]=new Attr("分机号码", "分机号码", AttrType.TYPE_String, true);
		out[9]=new Attr("话机状态", "话机状态", AttrType.TYPE_String, true);
		out[10]=new Attr("话机呼叫权限", "话机呼叫权限", AttrType.TYPE_String, true);
		out[11]=new Attr("网外呼叫权限", "网外呼叫权限", AttrType.TYPE_String, true);
		out[12]=new Attr("付费类型", "付费类型", AttrType.TYPE_String, true);
		out[13]=new Attr("短号通", "短号通", AttrType.TYPE_String, true);
		out[14]=new Attr("虚拟网标识", "虚拟网标识", AttrType.TYPE_String, true);
		out[15]=new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String, true);
		out[16]=new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取", AttrType.TYPE_String, false);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		WebService webService=new WebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get into arguments
		attrsIn.setClientSysName("CDMA");
		attrsIn.setFunctionName("getivpnkhxx");
		attrsIn.setRequestMessage("<mdn>"+(String) data.get("mdn")+"</mdn>");
		//Get soapxml
		String returnXml=webService.WebServiceInit(attrsIn);
		String flag=webService.getPattern("flag", returnXml);
		if(flag.equals("true")){
			map.put("ReturnCode", 0);
			map.put("Report", webService.getPattern("Report", returnXml));
			map.put("客户名称", webService.getPattern("客户名称", returnXml));
			map.put("客户号", webService.getPattern("客户号", returnXml));
			map.put("客户状态", webService.getPattern("客户状态", returnXml));
			map.put("分机短号最大长度", webService.getPattern("分机短号最大长度", returnXml));
			map.put("网内呼叫计费类别", webService.getPattern("网内呼叫计费类别", returnXml));
			map.put("物理号码", webService.getPattern("物理号码", returnXml));
			map.put("分机号码", webService.getPattern("分机号码", returnXml));
			map.put("话机状态", webService.getPattern("话机状态", returnXml));
			map.put("话机呼叫权限", webService.getPattern("话机呼叫权限", returnXml));
			map.put("网外呼叫权限", webService.getPattern("网外呼叫权限", returnXml));
			map.put("付费类型", webService.getPattern("付费类型", returnXml));
			map.put("短号通", webService.getPattern("短号通", returnXml));
			map.put("虚拟网标识", webService.getPattern("虚拟网标识", returnXml));
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "");
			map.put("flag",1);
		}else{
			map.put("flag",0);
			map.put("ReturnCode", 1);
			map.put("Report", "");
			map.put("客户名称", "");
			map.put("客户号","");
			map.put("客户状态", "");
			map.put("分机短号最大长度", "");
			map.put("网内呼叫计费类别", "");
			map.put("物理号码","" );
			map.put("分机号码", "");
			map.put("话机状态", "");
			map.put("话机呼叫权限", "");
			map.put("网外呼叫权限", "");
			map.put("付费类型", "");
			map.put("短号通","");
			map.put("虚拟网标识", "");
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		
		return map;
	}

}
